/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Tarea.Almacenamineto.GestorIO;
import Almacenamiento.*;
import java.util.Scanner;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
/**
 *
 * @author Willy
 */
public class PruebaGestorIO {
    //*******************************************************************
       public static void main(String args[]) {

        try {
            
                List<Atributo> attrs = new ArrayList<Atributo>();

                
                attrs.add(new Atributo("byte", Byte.class));
                attrs.add(new Atributo("short", Short.class));
                attrs.add(new Atributo("integer", Integer.class));
                attrs.add(new Atributo("long", Long.class));
                attrs.add(new Atributo("float", Float.class));
                attrs.add(new Atributo("double", Double.class));
                attrs.add(new Atributo("string", String.class));
                
                Relacion rel = new Relacion(attrs);
                //List<Comparable> v = new ArrayList<Comparable>();
            Scanner input = new Scanner( System.in );
            
            System.out.print("NRO DE TUPLA: ");
            int N = input.nextInt();
            
            for(int k = 1; k <= N; k++)
            {
                System.out.println("TUPLA (" + k + ") ");
                List<Comparable> v = new ArrayList<Comparable>();
                
                System.out.print("Byte: ");
                Byte by = input.nextByte();
                v.add(by);
                System.out.print("Short: ");
                Short sh = input.nextShort();
                v.add(sh);
                System.out.print("Integer: ");
                Integer in = input.nextInt();
                v.add(in);
                System.out.print("Long: ");
                Long log = input.nextLong();
                v.add(log);
                System.out.print("Float: ");
                Float flo = input.nextFloat();
                v.add(flo);
                System.out.print("Double: ");
                Double dou = input.nextDouble();
                v.add(dou);
                System.out.print("String: ");
                String str = input.next();
                v.add(str);
                
                IdentificadorTupla Id = new IdentificadorTupla("redes",k);
                
                Tupla t = new Tupla(Id, v);
                GestorIOTupla man = new GestorIOTupla(rel, "redes");
                java.io.RandomAccessFile raf = new java.io.RandomAccessFile("redes", "rw"); // acceso aleatorio al archivo

                System.out.println("Escribiendo la tupla..." + t);
                byte[] bytes = new byte[4096]; // Guardar archivo de 4kbyte

                //man.escribirTupla(t, raf);
                man.escribirTupla(t, bytes, k);
                raf.close();
              
                raf = new java.io.RandomAccessFile("redes", "r");

                System.out.print("Leendo tupla...");

                //t = man.leerTupla(bytes);

                Par<Tupla, Integer> st = man.leerTupla(bytes, k);
                System.out.println(st);
                raf.close();
              }
            
        } catch (Exception e) {

            System.err.println("Exception: " + e.getMessage());
            e.printStackTrace(System.err);
        }

    } // main()
    
 //**********************************************************************
    
} // GestorIOTupla


